module.exports = function ($scope, $modalInstance, FileUploader,$resource, $modal, item, flag, toaster){
    
    init();
    function init(){
        $scope.opeinfo = flag ? {'flag': true} : angular.copy(item);
        $resource('/api/as/mc/shopproduct/findMyProductNoPageList', {}, {}).save({}, function (res) {
			if (res.errcode === 0) {
				$scope.ProductList = res.data;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
        
    }
   
    //保存
    $scope.save = function (){
        var url =  flag ? '/api/as/mc/shopproduct/insertVoluntaryact' : '/api/as/mc/shopproduct/updateVoluntaryactInfo';
        if(flag){
            $scope.opeinfo.product_code = $scope.opeinfo.product.product_code;
            $scope.opeinfo.product = "";
        }
        $resource(url, {}, {}).save($scope.opeinfo, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }




    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }
};